home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Applications / QuArK / plugins / map3viewslayout.py < prev    next >
Text File  |  2004-01-05  |  7KB  |  253 lines

  1. """   QuArK  -  Quake Army Knife
  2.  
  3. Plug-in which define the Classical screen layout.
  4. """
  5. #
  6. # Copyright (C) 1996-99 Armin Rigo
  7. # THIS FILE IS PROTECTED BY THE GNU GENERAL PUBLIC LICENCE
  8. # FOUND IN FILE "COPYING.TXT"
  9. #
  10.  
  11. #$Header: /cvsroot/quark/runtime/plugins/map3viewslayout.py,v 1.2 2000/06/03 10:25:30 alexander Exp $
  12.  
  13.  
  14.  
  15. Info = {
  16.    "plug-in":       "3-Views Layout",
  17.    "desc":          "QuArK's 3-views Screen Layout.",
  18.    "date":          "23 nov 98",
  19.    "author":        "Armin Rigo",
  20.    "author e-mail": "arigo@planetquake.com",
  21.    "quark":         "Version 5.2" }
  22.  
  23.  
  24. from quarkpy.mapmgr import *
  25.  
  26.  
  27. #
  28. # The 3-views Layout is implemented as a subclass of the base class MapLayout.
  29. #
  30.  
  31. class ThreeViewsLayout(MapLayout):
  32.     "The 3-views QuArK layout."
  33.  
  34.     shortname = "3 views"
  35.  
  36.     def buildscreen(self, form):
  37.  
  38.         #
  39.         # We put the standard left panel first.
  40.         #
  41.  
  42.         self.bs_leftpanel(form)
  43.  
  44.         #
  45.         # Divide the main panel into two sections.
  46.         # horizontally, 1 section;
  47.         # vertically, 2 sections split at 40% of the height
  48.         #  (use "-0.4" instead of "0.4" to disable user resizing)
  49.         #
  50.  
  51.         form.mainpanel.sections = ((), (0.4,))
  52.  
  53.         #
  54.         # Create the XY view in the section (0,1), i.e. down.
  55.         #
  56.  
  57.         self.ViewXY = form.mainpanel.newmapview()
  58.         self.ViewXY.section = (0,1)
  59.  
  60.         #
  61.         # Create a panel in the top section.
  62.         #
  63.  
  64.         self.threeviews_toppanel = form.mainpanel.newpanel()
  65.         self.threeviews_toppanel.sections = ((0.65,), ())
  66.  
  67.         #
  68.         # Create the 3D and XZ views
  69.         #
  70.  
  71.         self.ViewXZ = self.threeviews_toppanel.newmapview()
  72.         self.View3D = self.threeviews_toppanel.newmapview()
  73.         self.View3D.section = (1,0)
  74.  
  75.         #
  76.         # Put these three views in the view lists.
  77.         #
  78.  
  79.         self.views[:] = [self.ViewXY, self.ViewXZ, self.View3D]
  80.         self.baseviews = self.views[:]
  81.  
  82.         #
  83.         # Setup initial display parameters.
  84.         #
  85.  
  86.         scale = 0.25   # default value
  87.  
  88.         self.ViewXY.info = {
  89.           "type": "XY",     # XY view
  90.           "angle": 0.0,     # compass angle
  91.           "scale": scale,   # scale
  92.           "vangle": 0.0}    # vertical angle
  93.  
  94.         self.ViewXZ.info = {
  95.           "type": "XZ",     # XZ view
  96.           "angle": 0.0,
  97.           "scale": scale,
  98.           "vangle": 0.0}
  99.  
  100.         self.View3D.info = {
  101.           "type": "3D"}     # 3D view
  102.  
  103.         #
  104.         # Link the horizontal position of the XZ view to that of the
  105.         # XY view, and remove the horizontal scroll bar of the XZ view.
  106.         #
  107.  
  108.         self.sblinks.append((0, self.ViewXZ, 0, self.ViewXY))
  109.         self.ViewXY.flags = self.ViewXY.flags &~ MV_HSCROLLBAR
  110.  
  111.  
  112.     #
  113.     # The following function is called when the configuration changed.
  114.     # We show or hide the red lines here.
  115.     #
  116.  
  117.     def setupchanged(self, level):
  118.  
  119.         #
  120.         # First call the inherited "setupchanged".
  121.         #
  122.  
  123.         MapLayout.setupchanged(self, level)
  124.  
  125.  
  126.         #
  127.         # Read the old flags and set both red lines by default.
  128.         #
  129.  
  130.         flagsXY = self.ViewXY.flags | MV_TOPREDLINE | MV_BOTTOMREDLINE
  131.         flagsXZ = self.ViewXZ.flags | MV_TOPREDLINE | MV_BOTTOMREDLINE
  132.  
  133.         #
  134.         # Remove the 2nd red line if required.
  135.         #
  136.  
  137.         if not MapOption("RedLines2"):
  138.             flagsXY = flagsXY &~ MV_TOPREDLINE
  139.             flagsXZ = flagsXZ &~ MV_BOTTOMREDLINE
  140.  
  141.         #
  142.         # Update the flags.
  143.         #
  144.  
  145.         self.ViewXY.flags = flagsXY
  146.         self.ViewXZ.flags = flagsXZ
  147.  
  148.  
  149.  
  150.     #
  151.     # The following function is called to compute the limits of
  152.     # the visible (non-grayed-out) areas for each map view.
  153.     #
  154.  
  155.     def setupdepth(self, view):
  156.  
  157.         #
  158.         # First check the "view" parameter.
  159.         #
  160.  
  161.         if (view is not self.ViewXY) and (view is not self.ViewXZ):
  162.             return
  163.  
  164.         #
  165.         # To compute the visible areas for the XY view, we
  166.         # get the rectangular area (in pixels) of the XZ view.
  167.         #
  168.  
  169.         x1,y1,x2,y2 = self.ViewXZ.redlinesrect
  170.  
  171.         #
  172.         # The line below does this :
  173.         #  * take a corner of the above rectangle
  174.         #  * compute the 3D coordinates of any point above this corner
  175.         # This gives a 3D point that is at the top limit of the visible area for the XY view.
  176.         #  * project this 3D point on the XY view
  177.         #  * keep only the z coordinate (i.e. the depth) of this projection
  178.         # This gives the depth of the top limit, which is what we wanted.
  179.         #
  180.         # The second line does the same for the other corner, which gives
  181.         # the bottom limit of the visible area.
  182.         #
  183.  
  184.         xydepth = (self.ViewXY.proj(self.ViewXZ.space(x1, y1, 0.0)).z,
  185.                    self.ViewXY.proj(self.ViewXZ.space(x2, y2, 0.0)).z)
  186.  
  187.         #
  188.         # Do it again for the XZ view...
  189.         #
  190.  
  191.         x1,y1,x2,y2 = self.ViewXY.redlinesrect
  192.         xzdepth = (self.ViewXZ.proj(self.ViewXY.space(x2, y2, 0.0)).z,
  193.                    self.ViewXZ.proj(self.ViewXY.space(x1, y1, 0.0)).z)
  194.  
  195.         #
  196.         # Depending on the draw mode, items may or may not be grayed
  197.         # out. If they are, we must redraw a view when the other one
  198.         # is scrolled, in case objects came in or out of view. This
  199.         # is done by calling "setdepth". Otherwise, we directly set
  200.         # the map view's "depth" attribute, which doesn't redraw the
  201.         # view.
  202.         #
  203.  
  204.         redraw = self.editor.drawmode & DM_MASKOOV
  205.  
  206.         if redraw and (view is not self.ViewXY):
  207.             self.ViewXY.setdepth(xydepth)
  208.         else:
  209.             self.ViewXY.depth = xydepth
  210.  
  211.         if redraw and (view is not self.ViewXZ):
  212.             self.ViewXZ.setdepth(xzdepth)
  213.         else:
  214.             self.ViewXZ.depth = xzdepth
  215.  
  216.  
  217.     #
  218.     # Functions to read and store the layout (window positions,...)
  219.     # in the Setup.
  220.     #
  221.  
  222.     def readconfig(self, config):
  223.         MapLayout.readconfig(self, config)
  224.         vsec = config["hvsec"]
  225.         if type(vsec)==type(()) and len(vsec)==2:
  226.             self.editor.form.mainpanel.sections = ((), vsec[:1])
  227.             self.threeviews_toppanel.sections = (vsec[1:], ())
  228.  
  229.     def writeconfig(self, config):
  230.         MapLayout.writeconfig(self, config)
  231.         hsec, vsec = self.editor.form.mainpanel.sections
  232.         hsec2, vsec2 = self.threeviews_toppanel.sections
  233.         config["hvsec"] = vsec + hsec2
  234.  
  235.  
  236.  
  237. #
  238. # Register the new layout.
  239. #
  240.  
  241. LayoutsList.append(ThreeViewsLayout)
  242.  
  243.  
  244. # ----------- REVISION HISTORY ------------
  245. #
  246. #
  247. # $Log: map3viewslayout.py,v $
  248. # Revision 1.2  2000/06/03 10:25:30  alexander
  249. # added cvs headers
  250. #
  251. #
  252. #
  253. #